<?php
class CarrinhoController extends Nadeb_Controller_Front
{
	
    public function init()
    {
    	parent::init();
    }

    public function indexAction()
    {
    	$cart = Site_Model_ShoppingCart::get_instance();
    	$this->view->carItens = $cart->getItens();
    	
//     	foreach ( $this->view->carItens as $pack )
// 	    	Nadeb_Debug::x( $pack->colors );
    }
    
    public function addAction()
    {
    	$products = new Site_Model_Products();
    	$cart = Site_Model_ShoppingCart::get_instance();
    	
    	$cart->add( $products->getProduct( $this->_getParam('id') ), $this->_getParam('size') );
    	
    	$this->view->carItens = $cart->getItens();
    	
    	$this->renderScript('carrinho/index.phtml');
    }
    
    public function removeAction()
    {
    	$cart = Site_Model_ShoppingCart::get_instance();
    	$cart->remove( $this->_getParam('id') );
    	$this->view->carItens = $cart->getItens();
    	$this->renderScript('carrinho/index.phtml');
    }
    
    public function sendAction()
    {
    	$payment = new Site_Model_PagSeguro();
    	$execCheckout = $payment->execCheckout();
    	
    	if(count($execCheckout->error) > 0)
    	{
    		echo 'comunicacao indisponivel no momento';
    		exit;
    	}
    	
    	header('Location: https://pagseguro.uol.com.br/v2/checkout/payment.html?code=' . $execCheckout->code);
    	die();
    }
    
}

